package com.lap.auth.adapter.driven.web.dict;

import com.lap.auth.application.dict.DictTypeAppService;
import com.lap.auth.application.dict.DictTypeQueryService;
import com.lap.auth.application.dict.command.CreateDictTypeCmd;
import com.lap.auth.application.dict.command.UpdateDictTypeCmd;
import com.lap.auth.application.dict.dto.DictTypeDto;
import com.lap.auth.application.dict.dto.QueryDictTypePageQuery;
import com.lap.framework.dto.page.PageResponse;
import com.lap.watchdog.starter.annotation.RepeatSubmit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "数据字典类型管理", description = "提供数据字典类型基本操作")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/dict-types")
public class DictTypeController {

  private final DictTypeAppService dictTypeAppService;
  private final DictTypeQueryService dictTypeQueryService;

  @Operation(summary = "获取字典类型")
  @GetMapping
  public PageResponse<DictTypeDto> getDictTypePage(QueryDictTypePageQuery query) {
    return dictTypeQueryService.queryDictTypePage(query);
  }

  @Operation(summary = "添加字典类型")
  @RepeatSubmit
  @PostMapping
  public Integer createDictType(@RequestBody @Valid CreateDictTypeCmd cmd) {
    return dictTypeAppService.createDictType(cmd);
  }

  @Operation(summary = "更新字典类型")
  @RepeatSubmit
  @PutMapping("{id}")
  public Integer updateDictType(
      @PathVariable Integer id, @RequestBody @Valid UpdateDictTypeCmd cmd) {
    return dictTypeAppService.updateDictType(id, cmd);
  }

  @Operation(summary = "删除字典类型")
  @RepeatSubmit
  @DeleteMapping("{id}")
  public Integer deleteDictType(@PathVariable Integer id) {
    return dictTypeAppService.deleteDictType(id);
  }
}
